package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "套餐管理类接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;


    @GetMapping("/page")
    @ApiOperation("分页查询套餐")
    public Result<PageResult> getCategoryList(CategoryPageQueryDTO categoryPageQueryDTO) {
        log.info("套餐分页查询，参数为{}",categoryPageQueryDTO);
        PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    @PostMapping
    @ApiOperation("新增套餐")
    public Result insert(@RequestBody CategoryDTO categoryDTO) {
        log.info("新增员工套餐，参数为:",categoryDTO);
    Category category = categoryService.save(categoryDTO);
    return Result.success(category);
    }

    @PutMapping
    @ApiOperation("修改套餐信息")
    public Result update(@RequestBody CategoryDTO categoryDTO) {
        log.info("修改套餐信息，参数为:{}",categoryDTO);
        Category category = categoryService.update(categoryDTO);
        return Result.success(category);
    }

    /*
    * 修改套餐状态
    * */
    @PostMapping("/status/{status}")
    @ApiOperation("启用或禁用套餐状态信息")
    public Result startorstop(@PathVariable("status") Integer status,Long id)
    {
        log.info("修改套餐状态信息,状态为:{},id为:{}",status,id);
            categoryService.startorstop(status,id);
            return Result.success();
    }

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> list(Integer type){
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }

    /*
    * 删除套餐或者菜品
    * */
    @DeleteMapping
    @ApiOperation("删除套餐或者菜品")
    public Result delete(Long id) {
        categoryService.deleteById(id);
        return Result.success();
    }
}
